//
//  TFTipsView.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/6.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit
import TFAnimatedImage
class TFTipsView: UIView {
    @objc public let view = UIView()
    @objc public let gif = UIView()
    @objc public let title = UILabel()
    @objc public let loadingExpression = TFAnimatedImageView()

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.black

        self.view.backgroundColor = UIColor.clear
        self.addSubview(self.view)

        self.view.addSubview(self.gif)
    
        self.loadingExpression.backgroundColor = UIColor.clear
        self.gif.addSubview(self.loadingExpression)

        let retinaPath = Bundle.main.path(forResource: "TF_turnAround", ofType: "gif")
        if retinaPath != nil {
            if let data = NSData(contentsOfFile: retinaPath! as String) {
                self.loadingExpression.animatedImage =  TFAnimatedImage.init(animatedGIFData: data as Data)
            }
        }

        
        self.title.font = UIFont.PingFang(size: 16)
        self.title.textAlignment = .center
        self.title.textColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1)
        self.view.addSubview(self.title)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let tipsViewW:CGFloat = 200;
        let tipsViewH:CGFloat  = 22.5+10+(106*0.8);
        let tipsViewX:CGFloat = (self.frame.size.width-tipsViewW)/2
        let tipsViewY:CGFloat = (self.frame.size.height-tipsViewH)/2
        // 圆角半径  能把一个下正文体,改成圆形
        // 设置裁剪
        self.view.layer.masksToBounds = true
        self.view.layer.cornerRadius = 8
     
        self.view.frame = CGRect(x: tipsViewX, y: tipsViewY, width: tipsViewW, height: tipsViewH)
    
        let gifWidth = 100*0.8;
        self.gif.frame = CGRect(x: (self.view.frame.size.width - gifWidth)/2, y: 0, width: gifWidth, height: (106*0.8))
      
        self.loadingExpression.frame = self.gif.bounds
        self.title.frame = CGRect(x: 0, y: self.view.frame.size.height-22.5, width: self.view.frame.size.width, height: 22.5)
     
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
}
